$(function () {
    load();
})

function fh() {
    localStorage.removeItem("mManufactureInsideSH");
    location.href = "../../wen_zhi_yi/mManufactureInsideSH.html";
}

function load() {
    let mManufacture = JSON.parse(localStorage.getItem("mManufactureInsideSH"));
    $("#register").text(mManufacture.register);
    $("#registerTime").text(mManufacture.registertime);
    $("#checker").text(mManufacture.checker);
    $("#checkTime").text(mManufacture.checktime);
    $("#manufactureId").text(mManufacture.manufactureid);
    $("#productId").text(mManufacture.productid);
    $("#productName").text(mManufacture.productname);
    $("#amount").text(mManufacture.amount);
    $("#designer").text(mManufacture.designer);
    $("#gongshi").text(mManufacture.labourcostpricesum);
    $("#wuliao").text(mManufacture.modulecostpricesum);
    $("#realModuleCostPriceSum").text(mManufacture.realmodulecostpricesum==null?'0.00':mManufacture.realmodulecostpricesum);
    $("#realLabourCostPriceSum").text(mManufacture.reallabourcostpricesum==null?'0.00':mManufacture.reallabourcostpricesum);
    $("#productDescribe").text(mManufacture.productdescribe);
    $("#remark").text(mManufacture.remark);
    $("#shu").val(mManufacture.amount);
    $("#testedamount").val(mManufacture.testedamount);

    $.post("/Mmanufacture.do/MmanufactureWZYDengJiSHlist", {id: mManufacture.id}, function (sdata) {
        let str = " <tr>\n" +
            "          <th>工序名称</th>\n" +
            "          <th>设计工时数</th>\n" +
            "          <th>实际工时数</th>\n" +
            "          <th>设计工时成本(元)</th>\n" +
            "          <th>实际工时成本</th>\n" +
            "          <th>设计物料成本(元)</th>\n" +
            "          <th>实际物料成本</th>\n" +
            "          <th>登记复核</th>\n" +
            "          <th>交接复核</th>\n" +
            "      </tr>\n";
        $.each(sdata, function (index, item) {
            let as = JSON.stringify(item);
            let procedurefinishtag =item.procedurefinishtag=='G004-0'?"未登记":
                item.procedurefinishtag=='G004-2'?"<a href='#' onclick='SH("+as+")'>复核</a>":
                    item.procedurefinishtag=='G004-1'?'已复核':'';

            let proceduretransfertag =item.proceduretransfertag=='G005-2'?"<a href='#' onclick='JJ("+as+")'>交接复核</a>":
                item.proceduretransfertag=='G005-1'?'已交接':'';
            str += "      <tr>\n" +
                "          <td>" + item.procedurename + "</td>\n" +
                "          <td>" + item.labourhouramount + "</td>\n" +
                "          <td>" + (item.reallabourhouramount == null ? '0.00' : item.reallabourhouramount) + "</td>\n" +
                "          <td>" + item.subtotal + "</td>\n" +
                "          <td>" + (item.realsubtotal == null ? '0.00' : item.realsubtotal) + "</td>\n" +
                "          <td>" + item.modulesubtotal + "</td>\n" +
                "          <td>" + (item.realmodulesubtotal == null ? '0.00' : item.realmodulesubtotal) + "</td>\n" +
                "          <td>" + procedurefinishtag + "</td>\n" +
                "          <td>" + proceduretransfertag + "</td>\n" +
                "      </tr>";
        })
        $("#tableCha").html(str);
    })
}

function SH(op) {
    localStorage.setItem("mManufactureInsideSH(1)",JSON.stringify(op));
    location.href="/wen_zhi_yi/mManufactureInsideSH(1)(01).html";
}



function JJ(op) {
    $("#SHJJModal").modal("show");
    sessionStorage.setItem("opid",JSON.stringify(op));
}
function qr() {
    let mManufacture = JSON.parse(localStorage.getItem("mManufactureInsideSH"));
    let opid = JSON.parse(sessionStorage.getItem("opid"));
    let testedamount = $("#testedamount").val();

    console.log(testedamount)
    console.log(mManufacture.amount)
    if (testedamount==""){
        alert("请填写本次工序合格产品数量！")
        $("#SHJJModal").modal("hide");
        return;
    }
    if (parseInt(testedamount)<0){
        alert("本次工序合格产品数量不能小于0")
        $("#SHJJModal").modal("hide");
        return;
    }
    if (parseInt(testedamount)>mManufacture.amount){
        alert("本次工序合格产品数量不能大于投产数量！")
        $("#SHJJModal").modal("hide");
    }else {
        let param={testedamount:parseInt(testedamount),mmfid:mManufacture.id,mid:opid.id};
        $.post("/Mmanufacture.do/MmanufactureDengJiAddSHJJ", param, function (data) {
            $("#SHJJModal").modal("hide");
            $("#testedamount").val(null);
            $("#shu").val(null);
            location.href="/wen_zhi_yi/mManufactureInsideSH.html";
        })
    }
}

